<?php
/**
 * Created by @baidu-aip
 * Author: ylang
 * Time: 2022/2/24 17:49
 */

namespace Hedgehog\BaiduAip;

class LaravelServiceProvider extends \Illuminate\Support\ServiceProvider
{

    public function register()
    {
        $this->setupConfig();

        $this->app->singleton(BaiduAip::class, function ($app) {
            return new BaiduAip(config('baidu_aip'));
        });

        $this->app->alias(BaiduAip::class, 'baidu_aip');
    }


    public function setupConfig()
    {
        $source = realpath(__DIR__.'/../config/baidu_aip.php');
        if ($this->app->runningInConsole()) {
            $this->publishes([$source => base_path('config/baidu_aip.php')], 'baidu_aip');
        }

        $this->mergeConfigFrom($source, 'baidu_aip');
    }

}